//
//  UIImage+XMKit.h
//  XMKit
//
//  Created by chenming on 2018/6/24.
//  Copyright © 2018年 ChenXiaoMing. All rights reserved.
//

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface UIImage (XMKit)

/** 中心拉伸的图片 */
// instancetype == UIImage
+ (UIImage *)stretchableImageNamed:(NSString *)name;

/** 图片缩小居中显示(清晰) */
+ (UIImage *)cutImageRect:(CGRect)rect image:(UIImage *)image;

/** 消除图片系统默认蓝色 */
+ (UIImage *)imageModeAlwaysOriginal:(NSString *)imageName;

/** 压缩图片 */
+ (UIImage*)originImage:(UIImage *)image scaleToSize:(CGSize)size;

/** 通过颜色获取一张宽高都为1px的图片 */
+ (UIImage *)imageWithColor:(UIColor *)color;

/** 通过颜色获取一张规定尺寸的图片 */
+ (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size;


+ (UIImage *)imageCompressForWidth:(UIImage *)sourceImage targetWidth:(CGFloat)defineWidth;

/** 将图片裁剪成一张圆形图片 */
- (UIImage *)clipCircleImageWithBorder:(CGFloat)borderWidth withColor:(UIColor *)borderColor;

/** 将图片压缩到指定宽度 */
- (UIImage *)compressWithWidth:(CGFloat)width;

/** 将图片在子线程中压缩，block在主线层回调，保证压缩到指定文件大小，尽量减少失真 */
- (void)compressToDataLength:(NSInteger)length withBlock:(void(^)(NSData *data))block;

/** 尽量将图片压缩到指定大小，不一定满足条件 */
- (void)tryCompressToDataLength:(NSInteger)length withBlock:(void(^)(NSData *data))block;

/** 快速将图片压缩到指定大小，失真严重 */
- (void)fastCompressToDataLength:(NSInteger)length withBlock:(void(^)(NSData *data))block;

/** 通过修改r.g.b像素点来处理图片 */
- (void)fliterImageWithFliterBlock:(void(^)(int *red, int *green, int *blue))Fliterblock success:(void(^)(UIImage *image))success;

@property (nonatomic, assign) BOOL isDecoded;

/**
 Message tip icon
 @param count     message count
 @param imageSize imageSize
 @param tipRadius tipRadius
 @param tipTop    topMargin
 @param tipRight  rightMargin
 @param fontSize  tipTextFontSize
 @param textColor tipTextColor
 @param tipColor  tipBackgroundColor
 @return New image with tip count in the top-right corner
 */
- (instancetype)messageImageWithCount:(NSInteger)count imageSize:(CGSize)imageSize tipRadius:(CGFloat)tipRadius tipTop:(CGFloat)tipTop tipRight:(CGFloat)tipRight fontSize:(CGFloat)fontSize textColor:(UIColor *)textColor tipColor:(UIColor *)tipColor;

@end

NS_ASSUME_NONNULL_END
